package com.fr.chart.core.glyph;

import com.fr.base.FRFont;
import com.fr.base.Inter;
import com.fr.base.core.GraphHelper;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.Axis;
import com.fr.chart.axis.TextAttr;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.core.ChartUtils;
import com.fr.report.cellElement.Formula;
import com.fr.report.script.core.FArray;
import com.fr.util.Utils;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import java.awt.Stroke;
import java.awt.geom.Dimension2D;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Point2D;
import java.awt.geom.Point2D.Double;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.awt.geom.RectangularShape;
import java.math.BigDecimal;
import java.text.Format;

public class RangeAxisGlyph extends ValueAxisGlyph
{
  private static final long serialVersionUID = -3771020074467579784L;
  public static final String XML_TAG = "RangeAxisGlyph";
  private Color leftColor = new Color(215, 214, 214);
  private Color rightColor = new Color(240, 239, 239);

  public RangeAxisGlyph()
  {
  }

  public RangeAxisGlyph(Axis paramAxis)
  {
    super(paramAxis);
  }

  public void setLeftColor(Color paramColor)
  {
    this.leftColor = paramColor;
  }

  public Color getLeftColor()
  {
    return this.leftColor;
  }

  public void setRightColor(Color paramColor)
  {
    this.rightColor = paramColor;
  }

  public Color getRightColor()
  {
    return this.rightColor;
  }

  public void init(Rectangle2D paramRectangle2D, double paramDouble)
  {
    setBounds(paramRectangle2D);
    setOrigin(new Point2D.Double(0.0D, paramRectangle2D.getHeight() / 2.0D));
    setAxisLength(paramRectangle2D.getWidth());
    setAxisGridLength(paramDouble);
  }

  public void drawTicks(Graphics paramGraphics)
  {
    label146: label286: label438: label450: Object localObject5;
    Format localFormat;
    String str;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    BasicStroke localBasicStroke1 = new BasicStroke(this.valueAxis.getSecStroke(), 1, 0);
    BasicStroke localBasicStroke2 = new BasicStroke(this.valueAxis.getMainStroke(), 1, 0);
    if (this.valueAxis.isLog())
    {
      if (this.tickLength > 1.0D)
      {
        d1 = getCrossValue();
        d2 = Math.log(d1) / Math.log(this.tickLength);
        while (d1 <= this.maxValue)
        {
          localObject3 = getTickLine(d1, this.valueAxis.getTickLength(), this.valueAxis.getTickMarkType());
          if (this.valueAxis.getTickLength() != 0)
          {
            if (this.valueAxis.getMainStroke() == 0.0F)
              break label146:
            drawTickLine(paramGraphics, (Line2D)localObject3, localBasicStroke2);
          }
          d1 = Math.exp(++d2 * Math.log(this.tickLength));
        }
      }
      if (this.smallTickLength <= 1.0D)
        break label450;
      d1 = getCrossValue();
      double d2 = Math.log(d1) / Math.log(this.smallTickLength);
      while (true)
      {
        if (d1 > this.maxValue)
          break label450;
        if ((d1 - getCrossValue()) / this.smallTickLength == 5.0D)
          break label286:
        localObject3 = getTickLine(d1, this.valueAxis.getSecTickLength(), this.valueAxis.getSecTickMarkType());
        if (this.valueAxis.getSecTickLength() != 0)
        {
          if (this.valueAxis.getSecStroke() == 0.0F)
            break label286:
          drawTickLine(paramGraphics, (Line2D)localObject3, localBasicStroke1);
        }
        d1 = Math.exp(++d2 * Math.log(this.smallTickLength));
      }
    }
    double d1 = (int)this.minValue;
    while (d1 <= this.maxValue)
    {
      localObject1 = getTickLine(d1, this.valueAxis.getTickLength(), this.valueAxis.getTickMarkType());
      drawTickLine(paramGraphics, (Line2D)localObject1, localBasicStroke2);
      d1 += this.tickLength;
    }
    d1 = (int)this.minValue;
    while (d1 <= this.maxValue)
    {
      if ((d1 - this.minValue) % this.tickLength == 0.0D)
        break label438:
      localObject1 = getTickLine(d1, this.valueAxis.getSecTickLength(), this.valueAxis.getSecTickMarkType());
      drawTickLine(paramGraphics, (Line2D)localObject1, localBasicStroke1);
      d1 += this.smallTickLength;
    }
    d1 = 1.0D;
    Object localObject1 = this.valueAxis.getShowUnit();
    if (localObject1 != null)
    {
      d1 = ValueAxis.getDivideUnit((String)localObject1);
      localObject2 = new TextGlyph(Inter.getLocText("Unit") + ":" + ((String)localObject1), null);
      localObject3 = new Rectangle(0, -45, 100, 20);
      ((TextGlyph)localObject2).setBounds((RectangularShape)localObject3);
      ((TextGlyph)localObject2).draw(localGraphics2D);
    }
    Object localObject2 = new BigDecimal(Double.toString(this.tickLength));
    if (this.valueAxis.isLog())
    {
      if (this.tickLength <= 1.0D)
        break label830;
      localObject3 = new BigDecimal(Double.toString(getCrossValue()));
      d3 = getCrossValue();
      while (true)
      {
        if (d3 > this.maxValue)
          break label830;
        localObject5 = ((BigDecimal)localObject3).multiply(new BigDecimal(Double.toString(1.0D / d1)));
        localFormat = getAxis().getFormat();
        str = "";
        if (localFormat != null)
          str = localFormat.format(Double.valueOf(((BigDecimal)localObject5).toString()));
        else
          str = ((BigDecimal)localObject5).toString();
        drawLabel(paramGraphics, d3, 0.0D, str);
        localObject3 = ((BigDecimal)localObject3).multiply((BigDecimal)localObject2);
        d3 *= this.tickLength;
      }
    }
    Object localObject3 = new BigDecimal(Double.toString(this.minValue));
    double d3 = this.minValue;
    while (d3 <= this.maxValue)
    {
      localObject5 = ((BigDecimal)localObject3).multiply(new BigDecimal(Double.toString(1.0D / d1)));
      localFormat = getAxis().getFormat();
      str = "";
      if (localFormat != null)
        str = localFormat.format(Double.valueOf(((BigDecimal)localObject5).toString()));
      else
        str = ((BigDecimal)localObject5).toString();
      drawLabel(paramGraphics, d3, 0.0D, str);
      localObject3 = ((BigDecimal)localObject3).add((BigDecimal)localObject2);
      d3 += this.tickLength;
    }
    if (this.valueAxis.hasAlertValue())
    {
      label830: localObject3 = this.valueAxis.getAlertValue();
      if (localObject3 != null)
        if (localObject3 instanceof Formula)
        {
          drawAlertValueLabel(paramGraphics, (this.maxValue - this.minValue) / 4.0D, 0.0D, Inter.getLocText("ChartF-Alert"));
        }
        else
        {
          if (localObject3 instanceof FArray)
          {
            localObject4 = (FArray)localObject3;
            int i = 0;
            while (true)
            {
              if (i >= ((FArray)localObject4).length())
                return;
              localObject5 = Utils.string2Number(((FArray)localObject4).elementAt(i).toString());
              if (localObject5 != null)
              {
                double d5 = ((Number)localObject5).doubleValue();
                if ((d5 >= getMinValue()) && (d5 <= getMaxValue()))
                  drawAlertValueLabel(paramGraphics, d5, 0.0D, ((FArray)localObject4).elementAt(i).toString());
              }
              ++i;
            }
          }
          Object localObject4 = Utils.string2Number(localObject3.toString());
          if (localObject4 != null)
          {
            double d4 = ((Number)localObject4).doubleValue();
            if ((d4 >= getMinValue()) && (d4 <= getMaxValue()))
              drawAlertValueLabel(paramGraphics, d4, 0.0D, localObject3.toString());
          }
        }
    }
  }

  protected void drawAxisGrid(Graphics paramGraphics)
  {
    Object localObject1;
    Object localObject2;
    double d1;
    Object localObject4;
    int j;
    Line2D[] arrayOfLine2D3;
    int l;
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    if ((getAxis().getSecondGridStyle() != 0) && (this.smallTickLength > 0.0D))
    {
      localObject1 = localGraphics2D.getStroke();
      localObject2 = localGraphics2D.getPaint();
      localGraphics2D.setStroke(GraphHelper.getStroke(getAxis().getSecondGridStyle()));
      localGraphics2D.setPaint(getAxis().getSecondGridColor());
      if (this.valueAxis.isLog())
      {
        if (this.smallTickLength <= 1.0D)
          break label256;
        d1 = getCrossValue();
        double d3 = Math.log(d1) / Math.log(this.smallTickLength);
        while (true)
        {
          if (d1 > this.maxValue)
            break label256;
          if ((d1 - getCrossValue()) / this.smallTickLength == 5.0D)
            break label166:
          arrayOfLine2D3 = getGridLine(d1);
          for (l = 0; l < arrayOfLine2D3.length; ++l)
            localGraphics2D.draw(arrayOfLine2D3[l]);
          label166: d1 = Math.exp(++d3 * Math.log(this.smallTickLength));
        }
      }
      d1 = this.minValue + this.smallTickLength;
      while (d1 <= this.maxValue)
      {
        Line2D[] arrayOfLine2D1 = getGridLine(d1);
        for (j = 0; j < arrayOfLine2D1.length; ++j)
          localGraphics2D.draw(arrayOfLine2D1[j]);
        d1 += this.smallTickLength;
      }
      label256: localGraphics2D.setPaint((Paint)localObject2);
      localGraphics2D.setStroke((Stroke)localObject1);
    }
    if ((getAxis().getMainGridStyle() != 0) && (this.tickLength > 0.0D))
    {
      localObject1 = localGraphics2D.getStroke();
      localObject2 = localGraphics2D.getPaint();
      localGraphics2D.setStroke(GraphHelper.getStroke(getAxis().getMainGridStyle()));
      localGraphics2D.setPaint(getAxis().getMainGridColor());
      if (this.valueAxis.isLog())
      {
        if (this.tickLength <= 1.0D)
          break label496;
        d1 = getCrossValue();
        double d4 = Math.log(d1) / Math.log(this.tickLength);
        while (true)
        {
          if (d1 > this.maxValue)
            break label496;
          arrayOfLine2D3 = getGridLine(d1);
          for (l = 0; l < arrayOfLine2D3.length; ++l)
            localGraphics2D.draw(arrayOfLine2D3[l]);
          d1 = Math.exp(++d4 * Math.log(this.tickLength));
        }
      }
      d1 = this.minValue + this.tickLength;
      while (d1 <= this.maxValue)
      {
        localObject4 = getGridLine(d1);
        for (j = 0; j < localObject4.length; ++j)
          localGraphics2D.draw(localObject4[j]);
        d1 += this.tickLength;
      }
      label496: localGraphics2D.setPaint((Paint)localObject2);
      localGraphics2D.setStroke((Stroke)localObject1);
    }
    if (this.valueAxis.hasAlertValue())
    {
      Line2D[] arrayOfLine2D2;
      int k;
      localObject1 = localGraphics2D.getPaint();
      localGraphics2D.setPaint(Color.RED);
      localObject2 = this.valueAxis.getAlertValue();
      if (localObject2 != null)
      {
        int i;
        if (localObject2 instanceof Formula)
        {
          localObject3 = getGridLine((this.maxValue - this.minValue) / 4.0D);
          i = 0;
          while (true)
          {
            if (i >= localObject3.length)
              break label790;
            localGraphics2D.draw(localObject3[i]);
            ++i;
          }
        }
        if (localObject2 instanceof FArray)
        {
          localObject3 = (FArray)localObject2;
          i = 0;
          while (true)
          {
            Line2D[] arrayOfLine2D4;
            int i1;
            if (i >= ((FArray)localObject3).length())
              break label790;
            localObject4 = Utils.string2Number(((FArray)localObject3).elementAt(i).toString());
            if (localObject4 != null)
            {
              double d5 = ((Number)localObject4).doubleValue();
              if ((d5 <= getMaxValue()) && (d5 >= getMinValue()))
              {
                arrayOfLine2D4 = getGridLine(d5);
                for (i1 = 0; i1 < arrayOfLine2D4.length; ++i1)
                  localGraphics2D.draw(arrayOfLine2D4[i1]);
              }
            }
            ++i;
          }
        }
        Object localObject3 = localObject2.toString();
        if (Utils.string2Number((String)localObject3) != null)
        {
          double d2 = Utils.string2Number((String)localObject3).doubleValue();
          if ((d2 <= getMaxValue()) && (d2 >= getMinValue()))
          {
            arrayOfLine2D2 = getGridLine(d2);
            for (k = 0; k < arrayOfLine2D2.length; ++k)
              localGraphics2D.draw(arrayOfLine2D2[k]);
          }
        }
      }
      label790: localGraphics2D.setPaint((Paint)localObject1);
    }
    drawAxisGround(localGraphics2D);
  }

  protected void drawAxisGround(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    Paint localPaint = localGraphics2D.getPaint();
    Point2D.Double localDouble1 = new Point2D.Double(0.0D, getBounds().getHeight() / 2.0D);
    Point2D.Double localDouble2 = new Point2D.Double(this.axisLength, getBounds().getHeight() / 2.0D);
    localGraphics2D.setPaint(new GradientPaint(localDouble1, getLeftColor(), localDouble2, getRightColor(), true));
    localGraphics2D.fill(new Rectangle2D.Double(0.0D, 0.0D, this.axisLength, getBounds().getHeight()));
    localGraphics2D.setPaint(localPaint);
  }

  protected Line2D[] getGridLine(double paramDouble)
  {
    Point2D localPoint2D = getPoint2DForSelf(paramDouble);
    Line2D.Double localDouble = new Line2D.Double(localPoint2D.getX(), localPoint2D.getY() - getAxisGridLength() / 2.0D, localPoint2D.getX(), localPoint2D.getY() + getAxisGridLength() / 2.0D);
    return new Line2D[] { localDouble };
  }

  protected void drawLabel(Graphics paramGraphics, double paramDouble1, double paramDouble2, String paramString)
  {
    Point2D localPoint2D = getPoint2DForSelf(paramDouble1 + paramDouble2);
    TextAttr localTextAttr = getAxis().getTextAttr();
    if (localTextAttr == null)
      localTextAttr = new TextAttr();
    Dimension2D localDimension2D = TextGlyph.calculateTextDimension(paramString, localTextAttr);
    Rectangle2D.Double localDouble = null;
    int i = this.valueAxis.getAxisLabelPosition();
    if (i == 0)
      return;
    if (i == 1)
      localDouble = new Rectangle2D.Double(localPoint2D.getX() - localDimension2D.getWidth() / 2.0D, localPoint2D.getY() + getBounds().getHeight() / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight());
    else if ((i == 2) || (i == 3))
      localDouble = new Rectangle2D.Double(localPoint2D.getX() - localDimension2D.getWidth() / 2.0D, localPoint2D.getY() - getBounds().getHeight() / 2.0D - localDimension2D.getHeight(), localDimension2D.getWidth(), localDimension2D.getHeight());
    TextGlyph.drawLabel(paramGraphics, paramString, localTextAttr, localDouble);
  }

  private void drawAlertValueLabel(Graphics paramGraphics, double paramDouble1, double paramDouble2, String paramString)
  {
    Point2D localPoint2D = getPoint2DForSelf(paramDouble1 + paramDouble2);
    TextAttr localTextAttr = new TextAttr();
    localTextAttr.setFRFont(FRFont.getInstance("SimSun", 12, 12, Color.red));
    Dimension2D localDimension2D = TextGlyph.calculateTextDimension(paramString, localTextAttr);
    Rectangle2D.Double localDouble = null;
    int i = this.valueAxis.getAxisLabelPosition();
    if (i == 0)
      return;
    if (i == 1)
      localDouble = new Rectangle2D.Double(localPoint2D.getX(), localPoint2D.getY() + getBounds().getHeight() / 2.0D, localDimension2D.getWidth(), localDimension2D.getHeight());
    else if ((i == 2) || (i == 3))
      localDouble = new Rectangle2D.Double(localPoint2D.getX(), localPoint2D.getY() - getBounds().getHeight() / 2.0D - localDimension2D.getHeight(), localDimension2D.getWidth(), localDimension2D.getHeight());
    TextGlyph.drawLabel(paramGraphics, paramString, localTextAttr, localDouble);
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Color"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("leftColor")) != null)
          setLeftColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("rightColor")) != null)
          setRightColor(new Color(Integer.parseInt(str2), true));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("RangeAxisGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Color");
    if (this.leftColor != null)
      paramXMLPrintWriter.attr("leftColor", getLeftColor().getRGB());
    if (this.rightColor != null)
      paramXMLPrintWriter.attr("rightColor", getRightColor().getRGB());
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof RangeAxisGlyph))
      return false;
    RangeAxisGlyph localRangeAxisGlyph = (RangeAxisGlyph)paramObject;
    if (!(super.equals(localRangeAxisGlyph)))
      return false;
    if (localRangeAxisGlyph.getLeftColor() != null)
    {
      if (localRangeAxisGlyph.getLeftColor().equals(getLeftColor()))
        break label56;
      return false;
    }
    if (getLeftColor() != null)
      return false;
    if (localRangeAxisGlyph.getRightColor() != null)
    {
      label56: if (localRangeAxisGlyph.getRightColor().equals(getRightColor()))
        break label88;
      return false;
    }
    label88: return (getRightColor() == null);
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    if (this.leftColor != null)
      localJSONObject.put("leftColor", ChartUtils.color2JS(this.leftColor));
    if (this.rightColor != null)
      localJSONObject.put("rightColor", ChartUtils.color2JS(this.rightColor));
    return localJSONObject;
  }

  public String getJSAxisType()
  {
    return "RangeAxisGlyph";
  }
}